package Order.Entity;

import java.io.Serializable;
import java.util.List;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlTransient;

@Entity
@NamedQueries({
  @NamedQuery(name = "Product.findAll", query = "select o from Product o"),
       @NamedQuery(name = "Product.findProductById", query = "select o from Product o where o.id = :id")
})
@Table(name = "products")
public class Product implements Serializable {
   @Column(name="description")
    private String description;
    @Id
    @Column(name="id")
    private Integer id;
    @Column(name="price")
    private Integer price;
    @OneToMany(mappedBy = "product")
    private List<OrderLine> orderlines;

    public Product() {
    }

    public Product(String description, Integer id, Integer price) {
        this.description = description;
        this.id = id;
        this.price = price;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Integer getPrice() {
        return price;
    }

    public void setPrice(Integer price) {
        this.price = price;
    }

    @XmlTransient
    public List<OrderLine> getOrderlines() {
        return orderlines;
    }

    public void setOrderlines(List<OrderLine> orderlineList) {
        this.orderlines = orderlineList;
    }

    public OrderLine addOrderline(OrderLine orderline) {
        getOrderlines().add(orderline);
        orderline.setProduct(this);
        return orderline;
    }

    public OrderLine removeOrderline(OrderLine orderline) {
        getOrderlines().remove(orderline);
        orderline.setProduct(null);
        return orderline;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Product)) {
            return false;
        }
        Product other = (Product) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "Order.Entity.Product[id=" + id + "]";
    }

}
